﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PublicClass;
using PublicClass.BreedingEnum;
using S.Breeding.Domain;
using S.Breeding.Read.Api.Application.Command.DeathManageCommand;
using S.Breeding.Read.Api.Application.Command.OustManageCommand;

namespace S.Breeding.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheeponlyController : ControllerBase
    {
        private readonly IMediator mediator;
        public SheeponlyController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        #region 死亡管理

        /// <summary>
        /// 死亡管理显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageInfo<DeathManage>> GetDeathManage([FromQuery]DeathManageListCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 反填死亡管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<DeathManage> EditDeathManage([FromQuery]DeathManageEditCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 死亡耳号管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<DeathManage>> EarDeathManage([FromQuery]DeathManageEarCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 显示死亡原因列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDeathCause()
        {
            List<object> list = new List<object>();
            foreach (DeathCause item in Enum.GetValues<DeathCause>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item
                });
            }
            return Ok(list);
        }
        #endregion

        #region 淘汰管理

        /// <summary>
        /// 淘汰管理显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageInfo<OustManage>> GetOustManage([FromQuery]OustManageListCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 淘汰管理反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<OustManage> EditOustManage([FromQuery]OustManageEditCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 显示淘汰原因列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetOustCause()
        {
            List<object> list = new List<object>();
            foreach (OustCause item in Enum.GetValues<OustCause>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item
                });
            }
            return Ok(list);
        }

        /// <summary>
        /// 显示是否离场列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetLingchatan()
        {
            List<object> list = new List<object>();
            foreach (Lingchatan item in Enum.GetValues<Lingchatan>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item
                });
            }
            return Ok(list);
        }
        /// <summary>
        /// 显示处理措施列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDispose()
        {
            List<object> list = new List<object>();
            foreach (Dispose item in Enum.GetValues<Dispose>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item
                });
            }
            return Ok(list);
        }
        #endregion

        [HttpGet]
        public async Task<List<OustManage>> GetSheepTypeTrue([FromQuery]OustManageFindCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
    }
}
